//
//  HistoryController.m
//  SleepingElf
//
//  Created by karong on 2023/10/26.
//

#import "HistoryController.h"
#import "HistoryCell.h"

@interface HistoryController ()
@property (weak, nonatomic) IBOutlet UICollectionView *listView;
@property (nonatomic, strong) NSArray * dataArray;
@end

@implementation HistoryController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self layoutListView];
}

- (void)layoutListView {
    self.dataArray = appConfig.playHistory;
    [self.listView reloadData];
}

- (IBAction)clearAction:(id)sender {
    [appConfig.playHistory removeAllObjects];
    [self layoutListView];
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.dataArray.count;
}

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    HistoryCell * historyCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HistoryCell" forIndexPath:indexPath];
    [historyCell setDataWithObject:self.dataArray[indexPath.row]];
    return historyCell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    CGSize size = CGSizeZero;
    size.width = SEScreenWidth - 13 - 13;
    size.height = 74;
    return size;
}

@end
